package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.controller.BaseController;
import com.hejjon.core.enumer.DatabaseTypeEnum;
import com.hejjon.domain.dto.DatabaseDTO;
import com.hejjon.domain.dto.DatabaseQueryDTO;
import com.hejjon.domain.vo.DatabaseTreeNodeVO;
import com.hejjon.domain.vo.DatabaseVO;
import com.hejjon.service.ISysDatabaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据库
 * @author: cs
 * @date: 2025-02-24 11:02:53
 * @since: 1.0
 */
@RestController
@RequestMapping("/datasource/database")
public class SysDatabaseController extends BaseController {


    @Resource
    private ISysDatabaseService databaseService;


    @GetMapping("/getDatabaseTreeData")
    public ResponseResult getDatabaseTreeData() {

        List<DatabaseTreeNodeVO> databaseTreeList = databaseService.findDatabaseTreeList();
        return success(databaseTreeList);
    }


    @PostMapping("/create")
    public ResponseResult create(@RequestBody DatabaseDTO database) {
        boolean b = databaseService.create(database);
        return toResult(b, "数据库创建成功");
    }


    @PostMapping("/list")
    public ResponseResult list(@RequestBody DatabaseQueryDTO queryDTO) {
        System.out.println("@@@@@@@@@@@@@@@@@@@@@queryDTO = " + queryDTO);
        List<DatabaseVO> list = databaseService.findList(queryDTO);
        return success(list);
    }

    @GetMapping("/getDatabaseTypes")
    public ResponseResult getDatabaseTypes() {
        return success(DatabaseTypeEnum.mapValues());
    }


    @PostMapping("/remove")
    public ResponseResult remove(@RequestBody DatabaseDTO dto) {
        return toResult(databaseService.remove(dto), "数据库删除成功");
    }






}
